package com.maxjay.component.metadata.core.command;

import java.util.ArrayList;
import java.util.List;

import com.maxjay.component.metadata.model.Entity;
import com.maxjay.component.metadata.model.Record;
import com.maxjay.component.metadata.service.EntityService;
import com.maxjay.system.core.Application;

/**
 * Entity的JDBC命令，需要使用EntityCommandProcessor执行器来执行此类命令，以保证在同一个事务中
 * 
 * @author zhaixm
 *
 */
public abstract class JdbcEntityCommand implements EntityCommand {

	protected Entity entity;
	
	protected List<Record> records = new ArrayList<Record>(0);
	
	public JdbcEntityCommand(Entity entity) {
		this.entity = entity;
	}
	
	public JdbcEntityCommand(Entity entity, Record record) {
		this.entity = entity;
		this.records.add(record);
	}

	public JdbcEntityCommand(Entity entity, List<Record> records) {
		this.entity = entity;
		this.records = records;
	}
	
	/**
	 * 返回Entity对象服务类
	 * 
	 * @return
	 */
	protected EntityService getEntityService() {
		return Application.getBeanContext().getBean("entityService", EntityService.class);
	}
	
	public Entity getEntity() {
		return entity;
	}

	public List<Record> getRecords() {
		return records;
	}

}
